#include "../head.h"

int main()
{
    int fd[2];
    int fp[2];
    pipe(fd);
    pipe(fp);

    pid_t pid = fork();

    if (pid > 0)
    {
        while (1)
        {
            char send[32]; //发送
            char receive[32]; //接收
            scanf("%s", send);
            write(fd[1], send, strlen(send));
            printf("parent send %s\n",send);
            if (strcmp(send, "exit") == 0)
            {
                break;
            } 

            read(fp[0], receive, 32);
            printf("parent receive %s\n",receive);
        }
        wait(NULL);
        
    }
    if (pid == 0)
    {
          while (1)
        {
            char send[32]; //发送
            char receive[32]; //接收
            read(fd[0], receive, 32);
            printf("child receive %s\n",receive);
            if (strcmp(receive, "exit") == 0)
            {
                exit(0);
            } 
            
            scanf("%s", send);
            write(fp[1], send, strlen(send));
            printf("child send %s\n",send);
        }
        
    }
    

}